package com.turnengine.client.local.message.bean;

import org.apache.commons.lang.builder.CompareToBuilder;
import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;

/**
 * The Local Message Content.
 */
public class LocalMessageContent implements ILocalMessageContent, Comparable<ILocalMessageContent> {

	/** The id. */
	private int id = -1;
	/** The content. */
	private String content = "";

	/**
	 * Creates a new Local Message Content.
	 */
	public LocalMessageContent() {
	}

	/**
	 * Creates a new Local Message Content.
	 * @param id the id
	 * @param content the content
	 */
	public LocalMessageContent(int id, String content) {
		setId(id);
		setContent(content);
	}

	/**
	 * Creates a new Local Message Content.
	 * @param localMessageContent the local message content
	 */
	public LocalMessageContent(LocalMessageContent localMessageContent) {
		setId(localMessageContent.getId());
		setContent(localMessageContent.getContent());
	}

	/**
	 * Creates a new Local Message Content.
	 * @param iLocalMessageContent the i local message content
	 */
	public LocalMessageContent(ILocalMessageContent iLocalMessageContent) {
		setId(iLocalMessageContent.getId());
		setContent(iLocalMessageContent.getContent());
	}

	/**
	 * Returns the id.
	 * @return the id.
	 */
	public int getId() {
		return id;
	}

	/**
	 * Returns the content.
	 * @return the content.
	 */
	public String getContent() {
		return content;
	}

	/**
	 * Sets the id.
	 * @param id the id to set.
	 */
	public void setId(int id) {
		this.id = id;
	}

	/**
	 * Sets the content.
	 * @param content the content to set.
	 */
	public void setContent(String content) {
		this.content = content;
	}

	/**
	 * Returns the hash code.
	 * @return the hash code.
	 */
	@Override
	public int hashCode() {
		HashCodeBuilder hash = new HashCodeBuilder(829, 37);
		hash.append(id);
		hash.append(content);
		return hash.toHashCode();
	}

	/**
	 * Returns true if this is equal to the given object.
	 * @param object the object to compare.
	 * @return true if this is equal to the given object.
	 */
	@Override
	public boolean equals(Object object) {
		if (object == this) {
			return true;
		}
		if (object instanceof LocalMessageContent) {
			LocalMessageContent compare = (LocalMessageContent) object;
			EqualsBuilder equals = new EqualsBuilder();
			equals.append(this.id, compare.id);
			equals.append(this.content, compare.content);
			return equals.isEquals();
		}
		return false;
	}

	/**
	 * Compare this to the given object.
	 * @param compare the object to compare to.
	 * @return the result of the comparison.
	 */
	@Override
	public int compareTo(ILocalMessageContent compare) {
		CompareToBuilder builder = new CompareToBuilder();
		builder.append(this.id, compare.getId());
		builder.append(this.content, compare.getContent());
		return builder.toComparison();
	}

	/**
	 * Returns this as a string.
	 * @return this as a string.
	 */
	@Override
	public String toString() {
		ToStringBuilder string = new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE);
		string.append("id", id);
		if (content != null) {
			string.append("content", content);
		}
		return string.toString();
	}
}
